﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ElingOA6_Admin_DSJCJ.BLL
{
    /// <summary>
    /// Paper业务逻辑简要说明。
    /// </summary>
    public class Paper
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public Paper()
        { }

        /// <summary>
        /// 组织机构DAL
        /// </summary>
        private readonly DAL.Paper dal = new DAL.Paper();

        /// <summary>
        /// 得到一个实体对象
        /// </summary>
        /// <creator>chenly</creator>
        /// <date>2013-7-25</date>
        /// <param name="fPaperId">主题编号</param>
        /// <returns>GetModel列表</returns>
        public Model.Paper GetModel(decimal fPaperId)
        {

            return dal.GetModel(fPaperId);
        }

        /// <summary>
        /// 某个调查类别是否存在该记录
        /// </summary>
        /// <param name="paperClsNo"></param>
        /// <param name="entityNo"></param>
        /// <returns></returns>
        public bool Exists(string paperClsNo, string entityNo)
        {
            return dal.Exists(paperClsNo, entityNo);
        }
        /// <summary>
        /// 获得数据列表
        /// <creator>chenly</creator>
        /// <date>2013-7-25</date>
        /// </summary>
       /// <param name="strWhere">查询条件</param>
        /// <returns>DataTableToList表</returns>
        public List<Model.Paper> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }

        /// <summary>
        /// 获得数据列表
        /// <creator>chenly</creator>
        /// <date>2013-7-25</date>
        /// </summary>
        /// <param name="dt">DataTable表</param>
        /// <returns>List</returns>
        public List<Model.Paper> DataTableToList(DataTable dt)
        {
            List<Model.Paper> modelList = new List<Model.Paper>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.Paper model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.Paper();
                    if (dt.Rows[n]["FPaperClsNo"] != null && dt.Rows[n]["FPaperClsNo"].ToString() != "")
                    {
                        model.FPaperClsNo = dt.Rows[n]["FPaperClsNo"].ToString();
                    }
                    if (dt.Rows[n]["FTitle"] != null && dt.Rows[n]["FTitle"].ToString() != "")
                    {
                        model.FTitle = dt.Rows[n]["FTitle"].ToString();
                    }
                    if (dt.Rows[n]["FContent"] != null && dt.Rows[n]["FContent"].ToString() != "")
                    {
                        model.FContent = dt.Rows[n]["FContent"].ToString();
                    }
                    if (dt.Rows[n]["FIsRecordName"] != null && dt.Rows[n]["FIsRecordName"].ToString() != "")
                    {
                        model.FIsRecordName = dt.Rows[n]["FIsRecordName"].ToString();
                    }
                    if (dt.Rows[n]["FBeginDate"] != null && dt.Rows[n]["FBeginDate"].ToString() != "")
                    {
                        model.FBeginDate = DateTime.Parse(dt.Rows[n]["FBeginDate"].ToString());
                    }
                    if (dt.Rows[n]["FEndDate"] != null && dt.Rows[n]["FEndDate"].ToString() != "")
                    {
                        model.FEndDate = DateTime.Parse(dt.Rows[n]["FEndDate"].ToString());
                    }
                    if (dt.Rows[n]["FResultIsOpen"] != null && dt.Rows[n]["FResultIsOpen"].ToString() != "")
                    {
                        model.FResultIsOpen = dt.Rows[n]["FResultIsOpen"].ToString();
                    }
                    if (dt.Rows[n]["FPaperId"] != null && dt.Rows[n]["FPaperId"].ToString() != "")
                    {
                        model.FPaperId = decimal.Parse(dt.Rows[n]["FPaperId"].ToString());
                    }
                    if (dt.Rows[n]["FEntityNo"] != null && dt.Rows[n]["FEntityNo"].ToString() != "")
                    {
                        model.FEntityNo = dt.Rows[n]["FEntityNo"].ToString();
                    }
                    if (dt.Rows[n]["FPubDate"] != null && dt.Rows[n]["FPubDate"].ToString() != "")
                    {
                        model.FPubDate = DateTime.Parse(dt.Rows[n]["FPubDate"].ToString());
                    }
                    if (dt.Rows[n]["FPubDeptNo"] != null && dt.Rows[n]["FPubDeptNo"].ToString() != "")
                    {
                        model.FPubDeptNo = dt.Rows[n]["FPubDeptNo"].ToString();
                    }
                    if (dt.Rows[n]["FPubEmpNo"] != null && dt.Rows[n]["FPubEmpNo"].ToString() != "")
                    {
                        model.FPubEmpNo = dt.Rows[n]["FPubEmpNo"].ToString();
                    }
                    if (dt.Rows[n]["FPubIp"] != null && dt.Rows[n]["FPubIp"].ToString() != "")
                    {
                        model.FPubIp = dt.Rows[n]["FPubIp"].ToString();
                    }
                    if (dt.Rows[n]["FPaperType"] != null && dt.Rows[n]["FPaperType"].ToString() != "")
                    {
                        model.FPaperType = dt.Rows[n]["FPaperType"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }
        /// <summary>
        /// 删除主题和主题权限 事务模式
        /// </summary>
        /// <creator>chenly</creator>
        /// <date>2013-7-25</date>
        /// <param name="paperID">主键ID</param>
        public void DelPapetAndReadAuth(decimal paperID)
        {
            dal.DelPapetAndReadAuth(paperID);
        }


        /// <summary>
        /// 增加主题和主题权限 事务模式
        /// </summary>
        /// <creator>chenly</creator>
        /// <date>2013-7-25</date>
        /// <param name="paperModel">主题对象</param>
        /// <param name="readAuthList">读者集合</param>
        /// <param name="paperIPList">IP集合</param>
       /// <returns>集合</returns>
        public decimal AddPaperAndReadAuth(Model.Paper paperModel, List<Model.PaperReadAuth> readAuthList, List<Model.PaperIP> paperIPList)
        {
            return dal.AddPaperAndReadAuth(paperModel, readAuthList, paperIPList);
        }


        /// <summary>
        /// 修改主题和查看权限 事务模式
        /// </summary>
        /// <creator>chenly</creator>
        /// <date>2013-7-25</date>
        /// <param name="paperModel">主题对象</param>
        /// <param name="readAuthList">读者集合</param>
        /// <param name="paperIPList">IP集合</param>
        public void UpdPaperAndReadAuth(Model.Paper paperModel, List<Model.PaperReadAuth> readAuthList, List<Model.PaperIP> paperIPList)
        {
            dal.UpdPaperAndReadAuth(paperModel, readAuthList, paperIPList);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        /// <creator>chenly</creator>
        /// <date>2013-7-25</date>
        /// <param name="dt">DataTable表</param>
        /// <returns>List集合</returns>
        public List<Model.Paper> DataTableToListPaper(DataTable dt)
        {
            List<Model.Paper> modelList = new List<Model.Paper>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.Paper model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.Paper();
                    if (dt.Rows[n]["FPaperClsName"] != null && dt.Rows[n]["FPaperClsName"].ToString() != "")
                    {
                        model.FPaperClsName = dt.Rows[n]["FPaperClsName"].ToString();
                    }
                    if (dt.Rows[n]["FPaperClsName"] != null && dt.Rows[n]["FPaperClsName"].ToString() != "")
                    {
                        model.FPaperClsName = dt.Rows[n]["FPaperClsName"].ToString();
                    }
                    if (dt.Rows[n]["FTitle"] != null && dt.Rows[n]["FTitle"].ToString() != "")
                    {
                        model.FTitle = dt.Rows[n]["FTitle"].ToString();
                    }
                    if (dt.Rows[n]["FBeginDate"] != null && dt.Rows[n]["FBeginDate"].ToString() != "")
                    {
                        model.FBeginDate = DateTime.Parse(dt.Rows[n]["FBeginDate"].ToString());
                    }
                    if (dt.Rows[n]["FEndDate"] != null && dt.Rows[n]["FEndDate"].ToString() != "")
                    {
                        model.FEndDate = DateTime.Parse(dt.Rows[n]["FEndDate"].ToString());
                    }
                    if (dt.Rows[n]["FPaperId"] != null && dt.Rows[n]["FPaperId"].ToString() != "")
                    {
                        model.FPaperId = decimal.Parse(dt.Rows[n]["FPaperId"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

    }
}
